package com.health.income.service.impl;

import com.health.common.security.utils.SecurityUtils;
import com.health.income.domain.ShmDoctor;
import com.health.income.domain.vo.ShmOrderSumVo;
import com.health.income.domain.vo.ShmOrderVO;
import com.health.income.mapper.IncomeMapper;
import com.health.income.service.IncomeService;
import com.health.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class IncomeServiceImpl implements IncomeService {

    @Autowired
    private IncomeMapper incomeMapper;

    /**
     * 查询我的收入
     * @return
     */
    @Override
    public List<ShmOrderVO> selectMyIncome() {

//        LoginUser loginUser = SecurityUtils.getLoginUser();
//        Long userid = loginUser.getUserid();

        ShmDoctor order = incomeMapper.getDoctor(1L);

        if (order == null){
            throw new RuntimeException("您还未注册医生");
        }

        ShmOrderSumVo shmOrderSumVo = incomeMapper.selectOrderSumByMonth(order.getId());

        List<ShmOrderVO> shmOrderVOS = incomeMapper.selectMyIncome(order.getId());

        for (ShmOrderVO shmOrderVO : shmOrderVOS) {
            shmOrderVO.setShmOrderSumVo(shmOrderSumVo);
        }

        return shmOrderVOS;
    }

    @Override
    public List<ShmOrderVO> selectMyOrder() {

        LoginUser loginUser = SecurityUtils.getLoginUser();
        Long userid = loginUser.getUserid();

        ShmDoctor order = incomeMapper.getDoctor(userid);

        List<ShmOrderVO> shmOrderVO = incomeMapper.selectMyOrder(order.getId());
        return shmOrderVO;
    }

    @Override
    public ShmOrderVO selectOrderInfo(Long orderId) {
        ShmOrderVO shmOrderVOS = incomeMapper.selectOrderInfo(orderId);
        if (shmOrderVOS == null){
            throw new RuntimeException("订单不存在");
        }
        return shmOrderVOS;
    }
}
